import { Menu, app } from 'electron'

function initMenu() {
  const { mainWindow } = global
  const template: Array<Electron.MenuItemConstructorOptions | Electron.MenuItem> = [
    {
      label: '应用',
      submenu: [
        { label: '关于我们', role: 'about' },
        {
          label: '检查更新',
          click: () => {
            mainWindow!.webContents.send('route:push', '/update')
            !mainWindow!.isVisible() && mainWindow!.show()
          }
        },
        { type: 'separator' },
        { label: '服务', role: 'services', submenu: [] },
        { type: 'separator' },
        { label: '退出', accelerator: 'CmdOrCtrl+Q', click: app.quit }
      ]
    },
    {
      label: '编辑',
      submenu: [
        { label: '复制', accelerator: 'CmdOrCtrl+C', role: 'copy' },
        { label: '粘贴', accelerator: 'CmdOrCtrl+V', role: 'paste' },
        { label: '剪切', accelerator: 'CmdOrCtrl+X', role: 'cut' },
        { label: '撤销', accelerator: 'CmdOrCtrl+Z', role: 'undo' },
        { label: '重做', accelerator: 'Shift+CmdOrCtrl+Z', role: 'redo' },
        { label: '全选', accelerator: 'CmdOrCtrl+A', role: 'selectAll' }
      ]
    }
  ]

  const menu = Menu.buildFromTemplate(template)
  Menu.setApplicationMenu(menu)
}
export { initMenu }
